<?php
/**
 * Author: DefinitlyEvil
 * Created at: 2020/4/15 18:06
 */

namespace App\Tools;


class GameModes
{
    const ALL = [
        'TEAM', 'EXPLOSIVE', 'BIO', 'SINGLE', 'CHALLENGE', 'BEDWARS', 'SKYWARS', 'UHC', 'HUNGERGAME'
    ];

    const TEAM = 'TEAM';
    const EXPLOSIVE = 'EXPLOSIVE';
    const BIO = 'BIO';
    const SINGLE = 'SINGLE';
    const CHALLENGE = 'CHALLENGE';

    const BEDWARS = 'BEDWARS';
    const SKYWARS = 'SKYWARS';
    const UHC = 'UHC';
    const HUNGERGAME = 'HUNGERGAME';

    public static function doesMapExist($gamemode, $map) {
        if(!Pattern::matches('/^[A-Z]{1,50}$/', $gamemode)) return false;
        if(!Pattern::matches('/^[A-Za-z0-9_\-]{1,50}$/', $map)) return false;
        $data = json_decode(file_get_contents('../maps.json'), true);
        if($data === false) return false;
        if(!isset($data[$gamemode])) return false;
        return in_array($map, $data[$gamemode], true);
    }

}
